<template>
  <div class="video" ref="video">
    <div class="jump" @click="jump">跳过</div>
  </div>
</template>

<script>
import music from '../utils/music'
import video from '../utils/video'
import { mapState } from 'vuex'

export default {
  data() {
    return {
      isJump: false
    }
  },
  computed: {
    ...mapState({
      up: state => state.up,
      down: state => state.down
    })
  },
  mounted() {
    music.pause()
    video.append(this.$refs.video)
    video.onEnd(() => {
      if (this.isJump) return;
      this.isJump = true;
      this.$store.dispatch('nextScene')
    })
    // video.onTouch(() => {
    //   if (/android/i.test(navigator.userAgent)) return;
    //   video.paused ? video.play() : video.pause()
    // })
    video.play()
    // video.pause()
  },
  methods: {
    jump() {
      this.isJump = true;
      this.$store.dispatch('nextScene')
    }
  },
  watch: {
    down(n) {
      if (n) {
        this.$store.dispatch('prevScene')
      }
    },
    up(n) {
      if (n) {
        this.$store.dispatch('nextScene')
      }
    }
  }
}
</script>

<style scoped>
.video {
  width: 100%;
  height: 100%;
  background-color: #000;
}
.jump {
  background: rgba(0, 0, 0, 0.5);
  padding: 0.2rem 0.4rem;
  border-radius: 0.2rem;
  color: #fff;
  font-size: 0.3rem;
  position: absolute;
  right: 0.2rem;
  top: 0.2rem;
  z-index: 2;
}
</style>
